<?php

namespace app\api\command;
use app\common\model\Packages;
use app\common\model\UserCommission;
use app\common\model\UserPackagesConfig;
use fast\Random;
use think\console\Command;
use think\console\Input;
use think\console\Output;

class Orderhexiao extends Command
{
    protected function configure()
    {
        $this->setName('hexiao')->setHelp('订单核销')->setDescription('订单核销');

    }

    protected function execute(Input $input, Output $output)
    {
        $orderModel = new \app\common\model\Order();
        $order =  $orderModel->with(['packages'])->whereNotNull('audit_upload_time')->where(['is_hexiao'=>3,'is_agency'=>1])->order('id desc')->select();
        $count  = 0;
        if($order){
            foreach ($order as $k=>$v){
                if(!empty($v['packages'])){
                    $audit_upload_time = $v['audit_upload_time']+$v['packages']['hexiao_day']*86400;
                    $end_time = strtotime(date('Y-m-d',$audit_upload_time));
                    if(time() > $end_time){
                        $v->is_hexiao = 3;
                        $v->hexiao_time = time();
                        $count += $v->save();
                    }else{
                        $v->is_hexiao = 1;
                        $v->hexiao_time = time();
                        $count += $v->save();
                    }
                }
            }
        }
       echo '处理数据--'.$count.'--条';
    }





}
